package org.sunflower.aliyun.ice;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 通过模板生成合成任务的请求参数
 * @author: TanJingyu
 * @create: 2021-10-11 21:51
 **/
public class SubmitMediaProducingJobRequestParam {
    private final ObjectMapper mapper = new ObjectMapper();
    private Map<String, Object> templateParam;
    private String outPutUrl;

    private SubmitMediaProducingJobRequestParam(){}

    public static Builder builder() {
        return new Builder(new HashMap<>(), new SubmitMediaProducingJobRequestParam());
    }

    public String getTemplateParam() {
        String result = "{}";
        try {
            result = mapper.writeValueAsString(this.templateParam);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return result;
    }

    public String getOutPut() {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("MediaURL", this.outPutUrl);

        String result = "{}";
        try {
            result = mapper.writeValueAsString(map);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return result;
    }

    public static class Builder {
        private SubmitMediaProducingJobRequestParam param;

        public Builder(HashMap<String, Object> kvHashMap, SubmitMediaProducingJobRequestParam submitMediaProducingJobRequestParam) {
            this.param = submitMediaProducingJobRequestParam;
            this.param.templateParam = kvHashMap;
        }

        public Builder templateParam(String key, Object value) {
            this.param.templateParam.put(key, value);
            return this;
        }

        public Builder outPutUrl(String outPutUrl) {
            this.param.outPutUrl = outPutUrl;
            return this;
        }

        public SubmitMediaProducingJobRequestParam build() {
            return param;
        }
    }
}
